package demo2;

public class LeetCode1004 {
    public int longestOnes(int[] nums, int k) {
        int n = nums.length, len = 0;
        int[] hash = new int[2];
        for (int left = 0, right = 0; right < n; right++) {
            hash[nums[right]]++;
            while (hash[0] > k) hash[nums[left++]]--;
            len = Math.max(len, right - left + 1);
        }
        return len;
    }
}
